package com.baize.minespace.controller;


import com.baize.minespace.pojo.PostTags;
import com.baize.minespace.service.PostTagsService;
import com.baize.minespace.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
 * 文章标签关联表 前端控制器
 * </p>
 *
 * @author baize
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/post-tags")
public class PostTagsController {
    @Autowired
    private PostTagsService postTagsService;

    @ApiModelProperty("新增文章标签关联表")
    @ApiOperation(value = "新增文章标签关联表", notes = "新增文章标签关联表")
    @PostMapping("add")
    public Result<Boolean> addPostTags(@RequestBody PostTags postTags){
        return Result.success(postTagsService.save(postTags));
    }

    @ApiModelProperty("删除文章标签关联表")
    @ApiOperation(value = "删除文章标签关联表", notes = "删除文章标签关联表")
    @GetMapping ("delete/{id}")
    public Result<Boolean> deletePostTags(@PathVariable(value = "id") Integer id) {
        return Result.success(postTagsService.removeById(id));
    }

    @ApiModelProperty("修改文章标签关联表")
    @ApiOperation(value = "修改文章标签关联表", notes = "修改文章标签关联表")
    @PostMapping("update")
    public Result<Boolean> updatePostTags(@RequestBody PostTags postTags) {
        return Result.success(postTagsService.updateById(postTags));
    }

    @ApiModelProperty("查询文章标签关联表")
    @GetMapping("select/{id}")
    public Result<PostTags> selectPostTags(@PathVariable(value = "id") Integer id) {
        return Result.success(postTagsService.getById(id));
    }

    @ApiModelProperty("分页查询文章标签关联表")
    @ApiOperation(value = "分页查询文章标签关联表", notes = "分页查询文章标签关联表")
    @GetMapping("page/{rows}/{page}")
    public Result<IPage<PostTags>> selectPostTagsPage(
        @PathVariable(value = "rows") Integer rows,
        @PathVariable(value = "page") Integer page,
        @RequestBody PostTags postTags
    ) {
        return postTagsService.selectPostTagsPage(rows, page, postTags);
    }
}
